package vn.sunnet.backviet01.game.coloa.human.enemy;

import org.anddev.andengine.entity.modifier.AlphaModifier;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.opengl.texture.region.TextureRegion;

public class BloodLine extends Sprite{
	private Sprite blood;
	private float part;
	
	private final float coefficient;
	
	public BloodLine(float pX, float pY, TextureRegion pTextureRegion, TextureRegion pBloodTextureRegion) {
		super(pX, pY, pTextureRegion);
		coefficient = pTextureRegion.getWidth() / pBloodTextureRegion.getWidth();
		this.blood = new Sprite(0, 0, pBloodTextureRegion);
		this.attachChild(blood);
		blood.setScaleCenter(0, blood.getTextureRegion().getWidth() / 2);
	}
	
	public void total(final float pBlood) {
		part = coefficient / pBlood;
	}
	
	public void updateScale(float pBlood) {
		try {
			if (pBlood < 0)
				pBlood = 0;
			blood.setScaleX(part * pBlood);
		} catch (Exception e) {
			pBlood = 0;
			blood.setScaleX(0);
		}
		this.clearEntityModifiers();
		
		AlphaModifier modifier = new AlphaModifier(2.0f, 1, 0);
		registerEntityModifier(modifier);
		
	}
	
}
